package com.jinzecloud.reportapproval.service.impl;

import com.jinzecloud.reportapproval.utils.R;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.Query;

import com.jinzecloud.reportapproval.mapper.InstrumentMapper;
import com.jinzecloud.reportapproval.bean.Instrument;
import com.jinzecloud.reportapproval.service.InstrumentService;


@Service("instrumentService")
public class InstrumentServiceImpl extends ServiceImpl<InstrumentMapper, Instrument> implements InstrumentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<Instrument> page = this.page(
                new Query<Instrument>().getPage(params),
                new QueryWrapper<Instrument>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<Instrument> getInstrument() {
        QueryWrapper<Instrument> instrumentQueryWrapper = new QueryWrapper<>(null);
        return this.list(instrumentQueryWrapper);
    }

    @Override
    public R saveInstrument(Instrument instrument) {
        String instrumentNumber = instrument.getInstrumentNumber();
        Instrument instrumentOne = this.getOne(new QueryWrapper<Instrument>().eq("instrument_number", instrumentNumber));
        if (instrumentOne == null){
            this.save(instrument);
        }else {
            return R.error().put("msg","已存在此编号的检测仪器");
        }
        return R.ok();
    }

}